home *** CD-ROM | disk | FTP | other *** search
/ Amiga Plus Special 25 / AMIGAplus Sonderheft 25 (2000)(Falke)(DE)(Track 1 of 4)[!].iso / PublicDomain / Anwendungen / UpDateCopy / Source / UpDateCopy.e
Text File  |  1998-07-04  |  36KB  |  1,147 lines

  1. /*
  2. ** ToDo: 160 may be used as space (32)
  3. */
  4.  
  5. /* UpDateCopy.e
  6. ** Copies multiple files/directories to one destination.
  7. ** Not existing directories are created.
  8. ** Already existing files are only replaced by newer ones
  9. ** (UpDateCopy first checks for versions-string and then
  10. **  for dates).
  11. **
  12. ** $VER: UpDateCopy.e 2.0 (04.07.98)
  13. **
  14. ** This program is Cardware. If you use it you should send an Email to
  15. ** the author. Also small presents are very welcome.
  16. ** You may use this sourcefile or parts of it freely in your programs.
  17. ** But please do not spread a modified version under this name (UpDateCopy).
  18. ** For Bugreports, ideas or anything else send a Email to:
  19. **    ss37@inf.tu-dresden.de
  20. ** 
  21. ** Sven Steiniger, 1996-98
  22. **
  23. ** Fold-start: ->// ""
  24. ** Fold-stop:  ->\\
  25. **
  26. ** History:
  27. **  2.0 : - FIXED: archive bit was modified in TESTMODE
  28. **        - slightly optimized copyfile()
  29. **        - FIXED: error during writing the last part of an file may be not recognized
  30. **  1.9 : - added PATTERN option to set the pattern used for recursiv scanning
  31. **  1.8 : - validateFilename() is much faster now
  32. **        - FIXED: sometimes forgot to unlock files
  33. **        - now works with strange patterns, eg. "Text (deutsch)/#?"
  34. **  1.7 : - UDC failed if it processes directories containing characters
  35. **          declared as wildcards (eg. "(" or "?").
  36. **          Note: standard "C:" commands fail here!! Just try
  37. **                'copy "WBStartup (Enabled)" ram:'
  38. **  1.6 : - changed getVersion() to recognize different version strings
  39. **          (eg. 'Test v1.0', 'Test 1', 'Test 2.')
  40. **  1.5 : - anchor structure was not longword aligned
  41. **      : - added lha-compatible date compare mode
  42. **  1.4 : - FIXED: directories may be created, even in testmode
  43. **      : - FIXED: protection bits may be modified in testmode
  44. **  1.3 : - the file-io buffer is now allocated once at start
  45. **      . - cleaned up
  46. **  1.2 : - fixed small bug in getVersion()
  47. **  1.1 : - uses now asyncio.library for fantastic speed
  48. **  1.00: - implemented SAB, CAB options
  49. **  0.54: - implemented NOASK-option
  50. **  0.53: - now user is asked on errors. Doesn't works perfect but I don't now
  51. **          how to implement it properly without adding to much extra code.
  52. **  0.52: - improved SMARTINFO-option
  53. **  0.51: - removed bug of version-scan-routines
  54. **  0.50: - added FAST-option
  55. **  0.49: - added SMARTINFO option
  56. **        - added wildcard-check. Now you can also use '*' as wildcard and
  57. **          you can also pass devices as sources (eq. ram:)
  58. **  0.48: - used exthelp-feature OF ReadArgs()
  59. **        - no longer needs 'c:copy'-command. Implemented an own routine.
  60. **  0.47: - file was not closed before SetProtection()/SetFileDate()
  61. **  0.46: - added PAPF-option -> archive protection flag is not changed
  62. **  0.45: - added CLONE-option -> Datestamp is copied
  63. **  0.44: - removed a unnecessary module. Saves 1K of executable size!
  64. **        - removed unnecessary ExamineFH()
  65. **        - now file gets only examined if really necessary
  66. **        - optimized a bit
  67. **        - FIXED: TESTMODE was buggy -> Directories were still created.
  68. **  0.43: - add new option TESTMODE; dont copy/replace files
  69. **  0.42: - add new option NODATECHECK; dont compare datestamps
  70. **  0.41: - replaced all reads/writes by fread/fwrite
  71. **  0.40: - first public release
  72. */
  73.  
  74. OPT OSVERSION=37
  75. OPT PREPROCESS
  76. OPT REG=5
  77.  
  78. MODULE 'dos/dos','dos/dosasl','dos/dostags','dos/rdargs','dos/stdio',
  79.        'asyncio','libraries/asyncio'
  80. MODULE 'sven/anchorPath',
  81.        'sven/eAddPart'
  82.  
  83. RAISE "MEM"  IF String()=NIL,
  84.       "^C"   IF CtrlC()=TRUE,
  85.       "copy" IF FileLength()=-1,
  86.       "MEM"  IF AllocDosObject()=NIL,
  87.       "fatt" IF SetProtection()=DOSFALSE,
  88.       "fatt" IF SetComment()=DOSFALSE,
  89.       "fatt" IF SetFileDate()=DOSFALSE
  90.  
  91.  
  92. #define OpenAsyncRead(filename) OpenAsync(filename,MODE_READ,ASYNCBUFFER)
  93. #define OpenAsyncWrite(filename) OpenAsync(filename,MODE_WRITE,ASYNCBUFFER)
  94. #define CloseAsyncRead(fh) CloseAsync(fh)
  95. #define CloseAsyncWrite(fh,exceptid) IF fh THEN IF CloseAsync(fh)<0 THEN Raise(exceptid)
  96. #define SafeReadAsync(fh,buffer,length,exceptid) IF ReadAsync(fh,buffer,length)<>(length) THEN Raise(exceptid)
  97. #define SafeWriteAsync(fh,buffer,length,exceptid) IF WriteAsync(fh,buffer,length)<>(length) THEN Raise(exceptid)
  98.  
  99. CONST MAXPATH=256,                -> Maximum path length
  100.       SPACEADD=3,                 -> Number of spaces per indent
  101.       SAFETYBYTES=150,            -> Maximum length of versionstring
  102.       BIGFILEMEM=16384            -> Files bigger than that are not read
  103.                                   -> completly into memory
  104.  
  105. CONST PATHLENGTH=MAXPATH-1,
  106.       BIGFILESIZE=BIGFILEMEM-SAFETYBYTES,
  107.       MAXPATH2=MAXPATH*2
  108.  
  109. CONST ASYNCBUFFER=BIGFILESIZE*2,
  110.       IOBUFFERSIZE=BIGFILEMEM+8   -> size of io-buffer (+8 'coz getVersion()
  111.                                   ->  may read 4 additional bytes)
  112.                                   
  113.  
  114. ENUM PDIR_Error,
  115.      PDIR_Skipped,
  116.      PDIR_Created
  117.  
  118. ENUM PFILE_Error,
  119.      PFILE_Skipped,
  120.      PFILE_Copied,
  121.      PFILE_Replaced
  122.  
  123. ENUM ASKUSER_Abort,
  124.      ASKUSER_Retry,
  125.      ASKUSER_Skip
  126.  
  127. DEF frompath[MAXPATH]:STRING,     -> actual sourcepath
  128.     fromlist:PTR TO LONG,         -> pointer to array of sourcestrings
  129.     topath[MAXPATH]:STRING,       -> destinationpath
  130.     doinfo,                       -> should we write informations ?
  131.     recursiv,                     -> scan recursively through subdirectories ?
  132.     ignoreprotection,             -> clear delete-protection ?
  133.     checkversion,                 -> compare version-strings ?
  134.     checkdates,                   -> compare datestamps ?
  135.     testmode,                     -> test modus ? (do not copy/replace files)
  136.     clone,                        -> copy datestamp ?
  137.     cleararchivebit,              -> clear archivebit OF copied file
  138.     smartinfo,                    -> only display copied/replaced files
  139.     fastdisplay,                  -> no linefeed
  140.     interaction,                  -> ask user on errors
  141.     setarchivebit,                -> set Archive bit
  142.     checkarchivebit,              -> check Archive bit
  143.     lousydatestamp,               -> lha compatible datestamp compare
  144.     subpattern[MAXPATH]:STRING,   -> pattern used to scan subdirectories/devices
  145.     dirlock=NIL                   -> PTR TO lock-structure OF destination path
  146.  
  147. DEF buffer=NIL:PTR TO CHAR        -> the global buffer used for all file-io.
  148.                                   -> Contains IOBUFFERSIZE Bytes
  149.  
  150. PROC main() HANDLE
  151. ->// "main()"
  152. DEF rdargs=NIL,
  153.     myargs:PTR TO LONG,
  154.     myrdargs=NIL:PTR TO rdargs,
  155.     exthelp[1000]:STRING
  156.  
  157.   asynciobase:=OpenLibrary('asyncio.library',39)
  158.   IF asynciobase=NIL THEN Raise("asio")
  159.  
  160.   /* Initialize argument-array */
  161.   myargs:=[
  162.            NIL,           -> fromlist
  163.            NIL,           -> destination path
  164.            FALSE,         -> ~showinfo
  165.            FALSE,         -> scan recursiv throuhg subdirectories
  166.            FALSE,         -> ignore protectionbits
  167.            FALSE,         -> deep scan
  168.            FALSE,         -> ~compare datestamps
  169.            FALSE,         -> testmode
  170.            FALSE,         -> clone
  171.            FALSE,         -> preserve archive protection flag
  172.            FALSE,         -> smartinfo
  173.            FALSE,         -> fastdisplay
  174.            FALSE,         -> interaction
  175.            FALSE,         -> set Archivebit
  176.            FALSE,         -> check Archivbit
  177.            FALSE,         -> precise datestamp
  178.            '#?'           -> subpattern
  179.           ]:LONG    
  180.  
  181.   myrdargs:=AllocDosObject(DOS_RDARGS,NIL)
  182.  
  183.   StrCopy(exthelp, '\n'+
  184.                    '  UpDateCopy v2.0\n'+
  185.                    ' -----------------\n'+
  186.                    '  Copy files and directories.\n'+
  187.                    '  Not existing directories are created and\n'+
  188.                    '  already existing files are only replaced\n'+
  189.                    '  by newer ones. Allows pattern-matching and\n'+
  190.                    '  multiple sourcedirectories/files.\n\n'+
  191.                    'Sven Steiniger, 1996-98\n'
  192.         )
  193.   StrAdd(exthelp,  '\n'+
  194.                    '  FROM        - source directory/file(s)\n'+
  195.                    '  TO          - dest